﻿$(document).ready(function (e) {
    $(".sff").click(function (e) {
        e.preventDefault();
        var c = $(this);
        if (c.hasClass("clearall")) {
            $(".clearall").removeClass("selected");
        } else {
            var a = c.find(">:first-child");

            var toClear = a.attr("id") == "ContentPlaceHolder1_MostReviewedSpan" ?
                    "HighRatingSpan" : "ContentPlaceHolder1_MostReviewedSpan";

            $("#" + toClear).removeClass("act_cheked");
            $("#" + toClear).addClass("uncheked");
            $("#" + toClear).parent().removeClass("selected");
            if (a.hasClass("uncheked")) {
                a.removeClass("uncheked");
                a.addClass("act_cheked");
            } else {
                a.removeClass("act_cheked");
                a.addClass("uncheked");
            }
        }
        c.toggleClass("selected");
    });
    $(".sff").click(function (e) {
        e.preventDefault();
        $("div.cat_search_left").html("<center><img src='img/loading2.gif' alt='loading'/></center>");
        var mostReviewed = $("#MostReviewed");
        var highRating = $("#HighRating");
        var minRating = $(".sff.clearall.selected");


        var wf = $("#fWifi");
        var oa = $("#fOpenAir");
        var minAmount = $("#slider-range").slider("option", "values")[0];
        var maxAmount = $("#slider-range").slider("option", "values")[1];


        var params = mostReviewed.hasClass("selected") + "|" +
                     highRating.hasClass("selected");
        if (minRating.size() != 0) {
            params += "|" + minRating.attr("f");
        } else {
            params += "|-1";
        }

        params += "|" + wf.hasClass("selected");
        params += "|" + oa.hasClass("selected");
        params += "|" + minAmount;
        params += "|" + maxAmount;

        var cts = $(".sff.ctss.selected");
        if (cts.size() != 0) {
            params += "|" + cts.size();
            cts.each(function (index) {
                params += "|" + $(this).attr("id");
            });
        } else {
            params += "|0";
        }
        CallServer(params, "");
    });
});
function ReceiveServerData(arg, context) {
    var parts = arg.split("|");
    switch (parts[0]) {
        case "Success":
            {
                $("div.cat_search_left").html(parts[1]);
                break;
            }
        case "Error":
            break;
        case "Fail":
            break; 
        default: break;
    } 
}
$(function () {
    $("#slider-range").slider({
        range: true,
        min: 0,
        max: 500,
        values: [5, 400],
        slide: function (event, ui) {
            $("#amount").val("$" + ui.values[0] + " - $" + ui.values[1]);
            delay(function () {
                $("div.cat_search_left").html("<center><img src='img/loading2.gif' alt='loading'/></center>");
                var mostReviewed = $("#MostReviewed");
                var highRating = $("#HighRating");
                var minRating = $(".sff.clearall.selected");
                var wf = $("#fWifi");
                var oa = $("#fOpenAir");
                var minAmount = $("#slider-range").slider("option", "values")[0];
                var maxAmount = $("#slider-range").slider("option", "values")[1];
                var params = mostReviewed.hasClass("selected") + "|" + highRating.hasClass("selected");
                if (minRating.size() != 0) {
                    params += "|" + minRating.attr("f");
                } else {
                    params += "|-1";
                }
                params += "|" + wf.hasClass("selected");
                params += "|" + oa.hasClass("selected");
                params += "|" + minAmount;
                params += "|" + maxAmount;
                var cts = $(".sff.ctss.selected");
                if (cts.size() != 0) {
                    params += "|" + cts.size();
                    cts.each(function (index) {
                        params += "|" + $(this).attr("id");
                    });
                } else {
                    params += "|0";
                }
                CallServer(params, "");
            }, 1000);
        }
    });
    $("#amount").val("$" + $("#slider-range").slider("values", 0) +
            " - $" + $("#slider-range").slider("values", 1));
    /*
    $("div.cat_search_left").html("<center><img src='img/loading.gif' alt='loading'/></center>");

    var mostReviewed = $("#MostReviewed");
    var highRating = $("#HighRating");

    var minRating = $(".sff.clearall.selected");


    var wf = $("#fWifi");
    var oa = $("#fOpenAir");
    var minAmount = $("#slider-range").slider("option", "values")[0];
    var maxAmount = $("#slider-range").slider("option", "values")[1];



    var params = mostReviewed.hasClass("selected") + "|" +
    highRating.hasClass("selected");
    if (minRating.size() != 0) {
    params += "|" + minRating.attr("f");
    } else {
    params += "|-1";
    }
    params += "|" + wf.hasClass("selected");
    params += "|" + oa.hasClass("selected");
    params += "|" + minAmount;
    params += "|" + maxAmount;
    CallServer(params, "");
     
    delay(function () {
    CallBacker.PerformCallback(SortID + "|@|" + DistanceID + "|@|" + PriceFrom + "|@|" + PriceTo + "|@|" + TypeID + "|@|" + SearchText);
    }, 1000);
    */
});
var delay = (function () { var timer = 0; return function (callback, ms) { clearTimeout(timer); timer = setTimeout(callback, ms); }; })();